//
//  Primer_Array_DemoVC.swift
//  APSwift
//
//  Created by AbnerPei on 2021/12/23.
//

import UIKit

class Primer_Array_DemoVC: UIViewController {

    deinit {
        debugPrint("123456 - Primer_Array_DemoVC deinit")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        /// 字符串拆分
        components()
        
        firstValue()
        
        /// 打乱顺序
        shuffled()
    }
    
    //MARK: 字符串拆分
    private func components() {
        let str = "com.abnerpei.china.520"
        let arr = str.components(separatedBy: ".")
        print("字符串拆分后的数组：\(arr)")
        /// 字符串拆分后的数组：["com", "abnerpei", "china", "520"]
    }
    /// 字符串拆分后的数组：["com", "abnerpei", "china", "520"]

    private func firstValue() {
        let messages: [String] = []
        if let str = messages.first {
            print("第一个元素是：\(str)")
        }
    }
}

//!!!: 打乱顺序
extension Primer_Array_DemoVC {
    func shuffled() {
        let numbers = [1, 2, 3, 4, 5, 6]
        let nums = numbers.shuffled()
        debugPrint("数组打乱：\(nums)")
        /// "数组打乱：[2, 6, 1, 3, 5, 4]"
    }
}
